<?php

namespace App\Admin\Controllers;

use App\model\City;
use App\model\Park;
use App\model\Workshop;
use App\model\WorkshopHangye;
use App\model\WorkshopIndustry;
use App\model\WorkshopPurpose;
use App\model\WorkshopTag;
use Carbon\Carbon;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class workshopReviewController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '待审盘源';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Workshop);

        $grid->column('title', __('厂房标题'));
        $grid->column('type', __('出租/出售类型'))->display(function ($value) {
            if ($value == 0) {
                return '出租';
            } else if ($value == 1) {
                return '出售';
            } else {
                return '可租可售';
            }
        });
        $grid->column('rent', __('租金'));
        $grid->column('price', __('价格'));
        $grid->column('area', __('建筑面积'));
        $grid->column('high', __('首层高度'));
        $grid->column('floor', __('楼层'));
        $grid->column('other_floor_high', __('二层及以上高度'));
        $grid->column('address', __('厂房地址'));
        $grid->column('distribution', __('配电类型'));
        $grid->column('park_id', __('园区'));
        $grid->column('ownertel', __('业主电话'));
        $grid->column('owner', __('业主名'));
        $grid->column('date_of_commission', __('委托日期'));
        $grid->column('commission_end_day', __('委托时效'));
        $grid->column('fuyong', __('佣金'));
        $states = [
            'on' => ['value' => 1, 'text' => '已审核', 'color' => 'success'],
            'off' => ['value' => 2, 'text' => '未审核', 'color' => 'danger'],
        ];
        $grid->column('shenhe', __('审核状态'))->switch($states);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Workshop::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('Title'));
        $show->field('rent', __('Rent'));
        $show->field('price', __('Price'));
        $show->field('type', __('Type'));
        $show->field('workshop_property_type_id', __('Workshop property type id'));
        $show->field('area', __('Area'));
        $show->field('area_id', __('Area id'));
        $show->field('tag', __('Tag'));
        $show->field('address', __('Address'));
        $show->field('built_area', __('Built area'));
        $show->field('high', __('High'));
        $show->field('floor', __('Floor'));
        $show->field('elevator', __('Elevator'));
        $show->field('distribution', __('Distribution'));
        $show->field('code', __('Code'));
        $show->field('owndesc', __('Owndesc'));
        $show->field('park_id', __('Park id'));
        $show->field('workshop_industry_id', __('Workshop industry id'));
        $show->field('ownertel', __('Ownertel'));
        $show->field('owner', __('Owner'));
        $show->field('slider', __('Slider'));
        $show->field('desc', __('Desc'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('logo', __('Logo'));
        $show->field('latitude', __('Latitude'));
        $show->field('longitude', __('Longitude'));
        $show->field('p_province_id', __('P province id'));
        $show->field('p_city_id', __('P city id'));
        $show->field('p_district_id', __('P district id'));
        $show->field('payratio', __('Payratio'));
        $show->field('matching_id', __('Matching id'));
        $show->field('property', __('Property'));
        $show->field('house_type', __('House type'));
        $show->field('is_recommend', __('Is recommend'));
        $show->field('click_count', __('Click count'));
        $show->field('call_count', __('Call count'));
        $show->field('is_out', __('Is out'));
        $show->field('owner_release', __('Owner release'));
        $show->field('reviewed', __('Reviewed'));
        $show->field('is_rent', __('Is rent'));
        $show->field('other_floor_high', __('Other floor high'));
        $show->field('weight', __('Weight'));
        $show->field('is_park', __('Is park'));
        $show->field('certificates', __('Certificates'));
        $show->field('status', __('Status'));
        $show->field('date_of_commission', __('Date of commission'));
        $show->field('commission_end_day', __('Commission end day'));
        $show->field('fuyong', __('Fuyong'));
        $show->field('hangyes', __('Hangyes'));
        $show->field('extend_tag', __('Extend tag'));
        $show->field('lianxi', __('Lianxi'));
        $show->field('contact', __('Contact'));
        $show->field('owner_company_name', __('Owner company name'));
        $show->field('geo', __('Geo'));
        $show->field('is_zhiding', __('Is zhiding'));
        $show->field('shenhe', __('Shenhe'));
        $show->field('user_id', __('User id'));
        $show->field('weight_id', __('Weight id'));
        $show->field('shenhe_role_id', __('Shenhe role id'));
        $show->field('changfang_type', __('Changfang type'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form($id=0)
    {
        $form = new Form(new Workshop);
        $type = [
            0 => '出租',
            1 => '出售',
            2 => '可租可售',
        ];
        $form->tab('基础信息',function(Form $form)use ($type,$id){
            $form->text('title', '厂房标题')->rules('required', [
                'required' => '请输入厂房标题'
            ])->help('必填项');
            $form->radio('type', '出租/出售类型')->options($type)->rules('required', [
                'required' => '请选择出租出售类型'
            ]);
            $form->currency('rent', '租金')->symbol("元/㎡")->help('不填写则面议')->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);
            $form->currency('price', '出售价格')->symbol("元/㎡")->help('不填写则面议')->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);
            $form->radio('is_rent','租赁方式')->options(
                Workshop::$rentMap
            );
            //   $form->number('payratio', '首付比例');
            $form->html(view('admin.status'));//这里是脚本
            //    $form->radio('fuyong', '付佣')->options(Workshop::$fuyongMap);
            $form->radio('status','状态')->options(Workshop::$statusMap)->rules('required', [
                'required' => '请选择状态'
            ]);;

            $form->dateRange('date_of_commission','commission_end_day','委托日期')->help('开始时间结束时间')->rules('required', [
                'required' => '请选择委托日期'
            ]);;
            $form->select('p_province_id', '城市')->options(City::getSelectOptions())->load('p_city_id', '/admin/api/area')->rules('required', [
                'required' => '请选择城市'
            ]);
            $form->select('p_city_id', '区域')->options(function ($id) {
                $id = $id ?: old('p_city_id');
                if($id)
                    return City::option($id);
            })->load('p_district_id', '/admin/api/area1')->rules('required', [
                'required' => '请选择区域'
            ]);
            $form->select('p_district_id', '下级区域')->options(function ($id) {
                $id = $id ?: old('p_district_id');
                if($id)
                    return City::option($id);
            });
            $form->text('address', '厂房地址')->rules('required', [
                'required' => '请选择厂房地址'
            ]);;
            $form->checkbox('industry', '类型')->options(WorkshopIndustry::getSelectOptions())->rules('required|array|max:2', [
                'required' => '类型',
                'max'=>'类型最多选择2项'
            ]);
            $form->checkbox('purpose', '用途')->options(WorkshopPurpose::getSelectOptions())->rules('required', [
                'required' => '用途'
            ]);
            $form->checkbox('hangye','适用行业')->options(WorkshopHangye::getSelectOptions())->rules('required', [
                'required' => '请选择适用行业'
            ]);;
            $form->radio('certificates','证件类型')->options(Workshop::$certificatesMap);
            $form->currency('area', '厂房面积（平方米）')->rules('required', [
                'required' => '请输入厂房面积'
            ])->symbol('平方米')->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);

            $form->currency('floor', '厂房所在楼层数')->symbol('层')->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,

            ]);
            $form->currency('high', '层高')->symbol("m")->options([
                'alias'              => 'currency',
                'radixPoint'         => '.',
                'removeMaskOnSubmit' => false,
            ]);
            $form->currency('weight','承重')->symbol('kg')->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);
            $form->currency('elevator', '电梯吨位')->symbol("T")->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);;
            $form->currency('distribution', '配电类型')->symbol("KW")->options([
                'alias'              => 'integer',
                'prefix'             => '',
                'removeMaskOnSubmit' => false,
            ]);;

            $form->hidden('code', '厂房编号')->default(Carbon::now()->timestamp);
            $form->checkbox('tags', '标签')->options(WorkshopTag::getSelectOptions())->rules('required', [
                'required' => '请输入标签'
            ]);;
            $form->tags('extend_tag', '自定义标签');
            $states = [
                'on' => ['value' => 1, 'text' => '推荐', 'color' => 'success'],
                'off' => ['value' => 0, 'text' => '不推荐', 'color' => 'danger'],
            ];
            $form->uploader('slider','轮播图')->rules('required|slider',[
                'required'=>"请添加图片",
                'slider'=>'图片不能少于十五张'
            ]);
            $form->ckeditor('owndesc', '厂房描述')->help('可输入内容的')->rules('required', [
                'required' => '请输入厂房描述',
                'slider'=>'图片不能少于15张'
            ]);
            $form->switch('is_recommend', '是否推荐')->states($states)->default(1);
            $states = [
                'on' => ['value' => 1, 'text' => '置顶', 'color' => 'success'],
                'off' => ['value' => 0, 'text' => '不置顶', 'color' => 'danger'],
            ];
            $form->switch('is_zhiding', '是否zhiding')->states($states)->default(0);
            $states = [
                'on' => ['value' => 1, 'text' => '已审核', 'color' => 'success'],
                'off' => ['value' => 2, 'text' => '未审核', 'color' => 'danger'],
            ];
            $form->switch('审核', '审核状态')->states($states)->default(2);
            $is_own = [
                0 => '否',
                1 => '是',
            ];
            //   $form->radio('owner_release', '是否业主发布')->options($is_own);
        })/*->tab('出售信息',function(Form $form){

        })*/->tab('业主信息',function(Form $form)use($id){
            $form->text('owner', '业主名称')->rules('required', [
                'required' => '请输入业主名称'
            ]);;
            $form->text('ownertel', '业主电话')->rules('required', [
                'required' => '请输入业主电话'
            ]);;
            $form->text('owner_company_name','业主公司名称');
            $form->contact('contact','看盘联系人')->options(compact('id'))->rules('required|contact',['required'=>'请填写看盘联系人','contact'=>'请填写看盘联系人']);
        })->tab('园区信息',function(Form $form){
            $form->radio('is_park', '是否园区')->options(Workshop::$parkMap);
            $form->select('park_id', ' 园区')->options(Park::getSelectOptions());
        });
        $form->tools(function (Form\Tools $tools){
            $tools->disableView();
        });
        $form->footer(function (Form\Footer $footer) {
            $footer->disableViewCheck();
            $footer->disableEditingCheck();
            $footer->disableCreatingCheck();
        });
        return $form;
    }
}
